home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
dm3_src.zip
/
DMDOS.C
< prev
next >
Wrap
Text File
|
1990-05-18
|
15KB
|
501 lines
/* ************************************************************************* */
/* */
/* D O O R W A R E D O S I N T E R F A C E L I B R A R Y */
/* */
/* For Mycrosoft & Turbo C */
/* */
/* ************************************************************************* */
/* */
/* This module contains functions used to input and output info */
/* with the user and remote_users console. Additionally, it */
/* contains functions that interface with DOS. */
/* */
/* The following funtions are contained in this file: */
/* */
/* get_dta - Get Disk Transfer Address */
/* fsearch - Search for files */
/* */
/* */
/* ************************************************************************* */
/* ************************************************************************* */
/* PROGRAM HISTORY */
/* ************************************************************************* */
/* 06/20/87 Version 1.00 */
/* */
/* */
/* */
/* */
/* ************************************************************************* */
#include "dmcfg.h" /* Std defines & includes */
#include "dmdata.h" /* Std DM storage */
/*
*
* Local module storage
*
*/
/*
*
* Open a file
*
*/
file_open(file, rw, mode, cflag) /* Open a file */
FS *file; /* File access structure */
int rw; /* 0 = read / 1 = modify */
/* 2 = append / 3 = write */
int mode; /* 0 = text / 1 = binary */
int cflag; /* Create if not exist */
{
int type;
int c1flag;
int share;
int share_open;
char stype[10];
type = 0;
c1flag = 1;
strcpy(stype, "\0");
switch(rw)
{
case 0: /* Read */
type = type | O_RDONLY;
#if COMPILER == MSC
share = SH_DENYNO;
#endif
#if COMPILER == BTC
share = O_DENYNONE;
#endif
strcat(stype, "r");
break;
case 1: /* Modify */
type = type | O_RDWR;
#if COMPILER == MSC
share = SH_DENYWR;
#endif
#if COMPILER == BTC
share = O_DENYWRITE;
#endif
strcat(stype, "r+");
break;
case 2: /* Append */
type = type | O_APPEND;
#if COMPILER == MSC
share = SH_DENYWR;
#endif
#if COMPILER == BTC
share = O_DENYWRITE;
#endif
strcat(stype, "a+");
break;
case 3: /* Write */
type = type | O_RDWR | O_TRUNC;
#if COMPILER == MSC
share = SH_DENYWR;
#endif
#if COMPILER == BTC
share = O_DENYWRITE;
#endif
strcat(stype, "w+");
break;
}
if(mode)
{
type = type | O_BINARY;
strcat(stype, "b");
}
if(_osmajor >= 3)
{
share_open = 1;
file->open_flag = -3;
}
else
{
share_open = 0;
file->open_flag = -1;
}
while(file->open_flag < 0)
{
if((_osmajor >= 3) && (share_open))
{
#if COMPILER == MSC
file->fh = sopen(file->name, type, share, S_IREAD | S_IWRITE);
#endif
#if COMPILER == BTC
file->fh = open(file->name, type | share, S_IREAD | S_IWRITE);
#endif
}
else
file->fh = open(file->name, type, S_IREAD | S_IWRITE);
if(file->fh == -1)
{
switch(errno)
{
case EACCES: /* Access violation */
file->open_flag++;
break;
case EEXIST: /* File already exists */
file->open_flag = 0;
return(-1);
break;
case EINVAL: /* SHARE.COM not installed */
share_open = 0;
break;
case EMFILE: /* No handles available */
file->open_flag = 0;
return(-2);
break;
case ENOENT: /* File not found */
if(cflag && c1flag)
{
type = type | O_CREAT;
stype[0] = 'w';
c1flag = 0;
file->open_flag--;
}
else
{
file->open_flag = 0;
return(-3);
}
break;
}
}
else
{
file->open_flag = rw + 1;
file->binary = mode;
file->fd = fdopen(file->fh, stype);
if(file->fd == 0L)
{
close(file->fh);
file->open_flag = 0;
return(-4);
}
return(0);
}
}
file->open_flag = 0;
return(-5);
}
/*
*
* Close a file
*
*/
file_close(file) /* Open a file */
FS *file;
{
fclose(file->fd);
close(file->fh);
file->open_flag = 0;
return(0);
}
/*
*
* Change current file access
*
*/
file_change(file, rw, mode, cflag) /* Open a file */
FS *file;
int mode; /* 0 = text, 1 = binary */
int cflag; /* 1 = create if not exist */
{
long ftell();
file->hold_flag = file->open_flag; /* Save previous state */
file->hold_mode = file->binary;
if(file->open_flag) /* if file was open */
{
file->hold_pos = ftell(file->fd); /* save previous position */
file_close(file);
return(file_open(file, rw, mode, FNOCREATE)); /* open it up */
}
return(file_open(file, rw, mode, cflag)); /* open it up */
}
/*
*
* Reset to previous access
*
*/
file_reset(file) /* Open a file */
FS *file;
{
int stat;
file_close(file); /* close it up */
stat = file_open(file, file->hold_flag - 1,
file->hold_mode, FNOCREATE); /* open it up */
if(stat) /* exit if error */
return(stat);
fseek(file->fd, file->hold_pos, 0); /* seek back to where we were */
return(0);
}
/*
*
* Get Disk Transfer Address
*
*/
char *get_dta() /* Pointer to return value */
{
union REGS inregs, outregs; /* DOS access structure */
struct SREGS segregs;
unsigned long temp; /* Work variable */
inregs.x.ax = 0x2f00; /* Get the address */
intdosx(&inregs, &outregs, &segregs);
temp = segregs.es; /* Convert to a pointer */
temp = temp << 16;
temp += outregs.x.bx;
return((char *)temp); /* return it */
}
/*
*
* Get Files
*
*/
fsearch(name, buffer)
char *name; /* Name to match */
char *buffer; /* Place to store matches */
{
char *get_dta();
union REGS inregs, outregs; /* DOS access structure */
struct SREGS segregs;
int count = 0; /* Match counter */
char *data_ptr; /* Search buffer */
char *fil_name; /* Filename pointer */
data_ptr = get_dta(); /* Get DTA address */
inregs.x.ax = 0x4e00; /* Search for 1st match */
inregs.x.cx = 0x0000;
segregs.ds = (unsigned long)name >> 16;
inregs.x.dx = (unsigned long)name & (unsigned long)0x0000ffff;
intdosx(&inregs, &outregs, &segregs);
if(outregs.x.ax != 0) /* If non found... */
return(0); /* ...then exit, 0 matches */
else
{
fil_name = data_ptr + 30; /* Point to filename */
while(*fil_name != '\0') /* Until we reach the end... */
{
*buffer = *fil_name; /* ...copy each char */
buffer++; /* ...bump the pointers */
fil_name++;
}
*buffer = 0; /* Terminate this string */
buffer++; /* Set for next filename */
count++; /* 1 more file matched */
}
while(1) /* Until we are done... */
{
inregs.h.ah = 0x4f; /* Search for next match */
inregs.x.cx = 0x0000;
segregs.ds = (unsigned long)name >> 16;
inregs.x.dx = (unsigned long)name & (unsigned long)0x0000ffff;
intdosx(&inregs, &outregs, &segregs);
if(outregs.x.ax) /* If no match... */
return(count); /* ...exit, with total */
else
{
fil_name = data_ptr + 30; /* Point to filename */
while(*fil_name != '\0') /* Until end of name... */
{
*buffer = *fil_name; /* ...copy each char */
buffer++; /* ...bump the pointers */
fil_name++;
}
*buffer = 0; /* Terminate the filename */
buffer++; /* Ready for next filename */
count++; /* 1 more match */
}
}
}
/*
*
* Get File Date
*
*/
fdate(name, buffer)
char *name; /* Name to match */
char *buffer; /* Place to store date */
{
char *get_dta();
union REGS inregs, outregs; /* DOS access structure */
struct SREGS segregs;
char string[10];
unsigned char *data_ptr; /* Search buffer */
unsigned int date; /* Date value */
int year, month, day;
data_ptr = (unsigned char *)get_dta(); /* Get DTA address */
inregs.x.ax = 0x4e00; /* Search for 1st match */
inregs.x.cx = 0x0000;
segregs.ds = (unsigned long)name >> 16;
inregs.x.dx = (unsigned long)name & (unsigned long)0x0000ffff;
intdosx(&inregs, &outregs, &segregs);
if(outregs.x.ax != 0) /* If non found... */
return(-1); /* ...then exit with error */
else
{
date = data_ptr[24]; /* Get the date value */
date += ((unsigned int)(data_ptr[25])) << 8;
year = (date & 0xfe00) >> 9; /* seperate the parts */
month = (date & 0x01e0) >> 5;
day = (date & 0x001f);
switch(month)
{
case 1: strcpy(buffer, "Jan");
break;
case 2: strcpy(buffer, "Feb");
break;
case 3: strcpy(buffer, "Mar");
break;
case 4: strcpy(buffer, "Apr");
break;
case 5: strcpy(buffer, "May");
break;
case 6: strcpy(buffer, "Jun");
break;
case 7: strcpy(buffer, "Jul");
break;
case 8: strcpy(buffer, "Aug");
break;
case 9: strcpy(buffer, "Sep");
break;
case 10: strcpy(buffer, "Oct");
break;
case 11: strcpy(buffer, "Nov");
break;
case 12: strcpy(buffer, "Dec");
break;
}
sprintf(string, " %2d", day);
strcat(buffer, string);
sprintf(string, " %4d\n", year + 1980);
strcat(buffer, string);
}
return(0);
}
/*
*
* Hide File
*
*/
fhide(filename)
char *filename; /* Name of file */
{
union REGS inregs, outregs; /* DOS access structure */
struct SREGS segregs;
inregs.x.ax = 0x4301; /* Hide the file */
inregs.x.cx = 0x0002;
segregs.ds = (unsigned long)filename >> 16;
inregs.x.dx = (unsigned long)filename & (unsigned long)0x0000ffff;
intdosx(&inregs, &outregs, &segregs);
if(outregs.x.ax != 0) /* If not set... */
return(-1); /* ...then exit with error */
else
return(0);
}
/*
*
* UnHide File
*
*/
funhide(filename)
char *filename; /* Name of file */
{
union REGS inregs, outregs; /* DOS access structure */
struct SREGS segregs;
inregs.x.ax = 0x4301; /* UnHide the file */
inregs.x.cx = 0x0000;
segregs.ds = (unsigned long)filename >> 16;
inregs.x.dx = (unsigned long)filename & (unsigned long)0x0000ffff;
intdosx(&inregs, &outregs, &segregs);
if(outregs.x.ax != 0) /* If not set... */
return(-1); /* ...then exit with error */
else
return(0);
}